package com.baomidou.springboot.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springboot.common.SortEnum;
import com.baomidou.springboot.entity.Authenticate;
import com.baomidou.springboot.mapper.AuthenticateMapper;
import com.baomidou.springboot.service.AuthenticateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 人才招聘 服务实现类
 * </p>
 *
 * @author QQQ
 * @since 2018-06-19
 */
@Service
public class AuthenticateServiceImpl implements AuthenticateService {

    @Autowired
    private AuthenticateMapper authenticateMapper;

    @Override
    public void save(Authenticate authenticate) {
        authenticate.setCreateDate(new Date());
        authenticateMapper.insert(authenticate);
    }

    @Override
    public void delete(String id) {
        authenticateMapper.deleteById(id);
    }

    @Override
    public Authenticate edit(String id) {
        return authenticateMapper.selectById(id);
    }

    @Override
    public void update(Authenticate authenticate) {
        authenticate.setModifyDate(new Date());
        authenticateMapper.updateById(authenticate);
    }

    @Override
    public Authenticate view(String id) {
        return authenticateMapper.selectById(id);
    }

    @Override
    public Page<Authenticate> list(Page<Authenticate> page, String search) {
        if (0 == page.getSize()) {
            page.setSize(10);
        }
        if (0 == page.getCurrent()) {
            page.setCurrent(1);
        }
        List<Authenticate> authenticateList = authenticateMapper.findByDateDesc(page, search);
        page.setRecords(authenticateList);
        return page;
    }

    @Override
    public void deleteBatch(List<String> ids) {
        if (null == ids) {
            return;
        }
        authenticateMapper.deleteBatchIds(ids);
    }

    @Override
    public Authenticate findById(String id) {
        return authenticateMapper.selectById(id);
    }

    @Override
    public List<Authenticate> findBySort() {
        return authenticateMapper.findBySort();
    }
}
